package com.example.demo.quartz;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

public class HelloMain {
    public static void main(String[] args) throws SchedulerException, InterruptedException {
        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();

        scheduler.getContext().put("skey", "hello");

        SimpleTrigger trigger = TriggerBuilder.newTrigger().
                withIdentity("trigger", "group1").
                usingJobData("t1", "tv1").
                withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInMilliseconds(3).repeatForever()).
                build();

        trigger.getJobDataMap().put("t2", "tv2");


        JobDetail jobDetail = JobBuilder.newJob(HelloJob.class).
                usingJobData("t3", "tv3")
                .usingJobData("t4", "4")
                .withIdentity("jobdetail", "mygroup").
                build();

        scheduler.scheduleJob(jobDetail,trigger);
        scheduler.start();

        Thread.sleep(5000);

        scheduler.pauseAll();

        Thread.sleep(1000);
        scheduler.clear();

    }
}
